package com.insurance.controller;

import com.insurance.common.Contants;
import com.insurance.common.ResultData;
import com.insurance.service.InsuranceService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * User1: 李辽
 * Date: 2020/10/27 10:47
 * Description:保险管理
 * Version: V1.0
 */
@Api(value = "被保险人信息",tags = "被保险人信息API")
@RequestMapping(value = "/insurance")
@Controller
public class InsuranceGlController {

    @Autowired
    private InsuranceService insuranceService;

    @RequestMapping(value = "/queryUser.do",method = RequestMethod.GET)
    @ApiOperation(value = "查询所有或者按条件查询被保险人信息",notes = "查询所有或者按条件查询被保险人信息接口",httpMethod = "get",response = ResultData.class)
    @ApiResponses({
            @ApiResponse(code=200,message="查询成功"),
            @ApiResponse(code=500,message="数据库暂无此相关数据"),
    })
    @ApiImplicitParams({
            @ApiImplicitParam(name = "user_phone", value = "用户手机号",dataType = "string",paramType = "query"),
    })
    @ResponseBody
    //查询所有或者按条件查询被保险人信息
    public ResultData queryUser(String user_phone){
        ResultData resultData = new ResultData();
        List<Map> mapList = insuranceService.queryInsuredUser(user_phone);
        if(mapList.size() > 0){
            resultData.setCode(Contants.SUCCESS);
            resultData.setMsg("查询成功");
            resultData.setData(mapList);
        }else {
            resultData.setCode(Contants.FAILURE);
            resultData.setMsg("数据库暂无此相关数据");
        }
        return resultData;
    }


    @RequestMapping(value = "/deleteUser.do",method = RequestMethod.GET)
    @ApiOperation(value = "查询车主卡里是否有该用户信息",notes = "查询车主卡里是否有该用户信息接口",httpMethod = "get",response = ResultData.class)
    @ApiResponses({
            @ApiResponse(code=200,message="车主卡里有该用户"),
            @ApiResponse(code=500,message="车主卡里无此用户"),
    })
    @ApiImplicitParams({
            @ApiImplicitParam(name = "user_name",value = "用户名称",dataType = "string",paramType = "query"),
            @ApiImplicitParam(name = "user_phone",value = "用户手机号",dataType = "string",paramType = "query"),
    })
    @ResponseBody
    //查询车主卡里是否有该用户信息接口
    public ResultData queryCardByNameOrPhone(String user_name,String user_phone){
        ResultData resultData = new ResultData();
        List<Map> map = insuranceService.queryCardByNameOrPhone(user_name,user_phone);
        if (map != null){
            resultData.setCode(Contants.SUCCESS);
            resultData.setMsg("车主卡里有该用户");
            resultData.setData(map);
        }else {
            resultData.setCode(Contants.FAILURE);
            resultData.setMsg("车主卡里无此用户");
        }
        return resultData;
    }



    @RequestMapping(value = "/queryAllInformation.do",method = RequestMethod.GET)
    @ApiOperation(value = "查询被保险人的所有信息",notes = "查询被保险人的所有信息接口",httpMethod = "get",response = ResultData.class)
    @ApiResponses({
            @ApiResponse(code=200,message="被保险人信息查询成功"),
            @ApiResponse(code=500,message="数据库暂无此数据"),
    })
    @ApiImplicitParams({
            @ApiImplicitParam(name = "user_id",value = "用户id",dataType = "int",paramType = "query"),
            @ApiImplicitParam(name = "insurance_id",value = "保单id",dataType = "int",paramType = "query"),
    })
    @ResponseBody
    //查询被保险人的所有信息接口
    public ResultData queryAllInformation(int user_id,int insurance_id){
        ResultData resultData = new ResultData();
        List<Map> map = insuranceService.queryAllInformation(user_id,insurance_id);
        if (map != null){
            resultData.setCode(Contants.SUCCESS);
            resultData.setMsg("被保险人信息查询成功");
            resultData.setData(map);
        }else{
            resultData.setCode(Contants.FAILURE);
            resultData.setMsg("数据库暂无此数据");
        }
        return resultData;
    }








    @RequestMapping(value = "/editUser.do",method = RequestMethod.POST)
    @ApiOperation(value = "更改保单信息",notes = "更改保单信息接口",httpMethod = "post",response = ResultData.class)
    @ApiResponses({
            @ApiResponse(code=200,message="修改成功"),
            @ApiResponse(code=500,message="后台服务错误"),
    })
    @ApiImplicitParams({
            @ApiImplicitParam(name = "insurance_id",value = "保单id",dataType = "int",paramType = "query"),
            @ApiImplicitParam(name = "user_name",value = "用户名称",dataType = "string",paramType = "query"),
            @ApiImplicitParam(name = "user_phone",value = "用户手机号",dataType = "string",paramType = "query"),
            @ApiImplicitParam(name = "high_stime",value = "交强保单起始时间",dataType = "String",paramType = "query"),
            @ApiImplicitParam(name = "high_ltime",value = "交强保单结束时间",dataType = "String",paramType = "query"),
            @ApiImplicitParam(name = "business_ftime",value = "商业保单起始时间",dataType = "String",paramType = "query"),
            @ApiImplicitParam(name = "business_ltime",value = "商业保单结束时间",dataType = "String",paramType = "query"),
            @ApiImplicitParam(name = "insure_amount",value = "保险价格",dataType = "double",paramType = "query"),

    })
    @ResponseBody
    //更改保单信息接口
    public ResultData editUser(@RequestBody Map map){
        System.out.println("=========从前端获取到的修改保单信息："+map.toString()+"=========");
        int result = insuranceService.editInsurance(map);
        ResultData resultData = new ResultData();
        if (result > 0){
            resultData.setCode(Contants.SUCCESS);
            resultData.setMsg("修改成功");
        }else {
            resultData.setCode(Contants.FAILURE);
            resultData.setMsg("后台服务错误");
        }
        return resultData;
    }



    @RequestMapping(value = "/addUser.do",method = RequestMethod.POST)
    @ApiOperation(value = "添加保单信息",notes = "添加保单信息接口",httpMethod = "post",response = ResultData.class)
    @ApiResponses({
            @ApiResponse(code=200,message="添加成功"),
            @ApiResponse(code=500,message="后台服务错误"),
    })
    @ApiImplicitParams({
            @ApiImplicitParam(name = "user_name",value = "用户名称",dataType = "string",paramType = "query"),
            @ApiImplicitParam(name = "user_phone",value = "用户手机号",dataType = "string",paramType = "query"),
            @ApiImplicitParam(name = "insure_amount",value = "车牌号",dataType = "string",paramType = "query"),
            @ApiImplicitParam(name = "insurance_com_id",value = "保险公司id",dataType = "int",paramType = "query"),
            @ApiImplicitParam(name = "high_insurance",value = "交强保单号",dataType = "string",paramType = "query"),
            @ApiImplicitParam(name = "business_insurance",value = "商业保单号",dataType = "String",paramType = "query"),
            @ApiImplicitParam(name = "high_stime",value = "交强保单起始时间",dataType = "String",paramType = "query"),
            @ApiImplicitParam(name = "high_ltime",value = "交强保单结束时间",dataType = "String",paramType = "query"),
            @ApiImplicitParam(name = "business_ftime",value = "商业保单起始时间",dataType = "String",paramType = "query"),
            @ApiImplicitParam(name = "business_ltime",value = "商业保单结束时间",dataType = "String",paramType = "query"),
            @ApiImplicitParam(name = "insure_id",value = "投保险种id",dataType = "int",paramType = "query"),
            @ApiImplicitParam(name = "owner_card_id",value = "车主卡id",dataType = "int",paramType = "query"),
    })
    @ResponseBody
    public ResultData addProtect(@RequestBody Map map){
        System.out.println("==========增加保单时前端输入的数据为：============="+map.toString());
        ResultData resultData =  insuranceService.addProtect(map);
        return resultData;
    }
}
